var addDigits = function(num) {
  let n = num;
  while(true){
      let sum = 0;
      while(n /10 > 0){
          sum += n%10;
          n = Math.floor(n/ 10);
      }
      if(Math.floor(sum/ 10) === 0){
          return sum;
      }else{
          n = sum;
      }
  }
};
console.log(addDigits(217));